package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsCouponUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class CouponUserServiceImpl implements CouponUserService {
    @Autowired
    private DtsCouponUserMapper couponUserMapper;

    @Override
    public IPage<DtsCouponUser> list(Integer couponId,
                                     Integer page, Integer limit,
                                     String sort, String order) {
        IPage<DtsCouponUser> iPage = new Page<>(page,limit);
        QueryWrapper<DtsCouponUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);

        if (!StringUtils.isEmpty(couponId)){
            queryWrapper.eq("coupon_id",couponId);
        }

        if ("asc".equalsIgnoreCase(order)){
            queryWrapper.orderByAsc(sort);
        }else {
            queryWrapper.orderByDesc(sort);
        }
        IPage<DtsCouponUser> couponUserIPage = couponUserMapper.selectPage(iPage, queryWrapper);

        return couponUserIPage;
    }
}
